// 状态码和状态信息定义
// @author ishot

package result

// Codes 定义状态
type Codes struct {
	Message               map[uint]string
	Success               uint
	Failed                uint
	SysMenuIsExist        uint
	DelSysMenuFailed      uint
	NorDeleteMenu         uint
	RoleAlreadyExists     uint
	RoleSysRoleFailed     uint
	MissParameter         uint
	UsernameAlreadyExists uint
	StatusDisabled        uint
	SysAdminIsNotExists   uint
	PasswordNotTrue       uint
	EmailCodeError        uint
}

// ApiCode 状态码
var ApiCode = &Codes{
	Success:               200,
	Failed:                501,
	SysMenuIsExist:        600,
	DelSysMenuFailed:      601,
	NorDeleteMenu:         602,
	RoleAlreadyExists:     603,
	RoleSysRoleFailed:     604,
	MissParameter:         605,
	UsernameAlreadyExists: 606,
	StatusDisabled:        607,
	SysAdminIsNotExists:   608,
	PasswordNotTrue:       609,
}

// 状态信息
func init() {
	ApiCode.Message = map[uint]string{
		ApiCode.Success:               "成功",
		ApiCode.Failed:                "失败",
		ApiCode.SysMenuIsExist:        "菜单名称已存在， 请重新输入",
		ApiCode.DelSysMenuFailed:      "菜单已分配角色不能删除",
		ApiCode.NorDeleteMenu:         "存在子菜单不能删除",
		ApiCode.RoleAlreadyExists:     "角色名称或角色key已存在，请重新输入",
		ApiCode.RoleSysRoleFailed:     "角色已分配用户不能删除",
		ApiCode.MissParameter:         "缺少必填参数",
		ApiCode.UsernameAlreadyExists: "用户名称已存在",
		ApiCode.StatusDisabled:        "你的账号已被停用，请联系系统管理员",
		ApiCode.SysAdminIsNotExists:   "用户不存在",
		ApiCode.PasswordNotTrue:       "密码不正确",
	}
}

// GetMessage 供外部调用
func (c *Codes) GetMessage(code uint) string {
	message, ok := c.Message[code]
	if !ok {
		return ""
	}
	return message
}
